export default {
	namespaced:true,
	state(){
		return {
			city:'定位中...'
		}
	},
	mutations:{
		initCityMut(state,city){
			state.city = city
		}
	},
	actions:{
		initLocAction(context){
			uni.getLocation({
				success: ({longitude,latitude}) => {
					console.log(longitude,latitude);
					let url = `https://restapi.amap.com/v3/geocode/regeo?key=6c6f187b43a18982bb5a2e2dfa2399e6&location=${longitude},${latitude}`
					uni.request({
						url,
						success: (res) => {
							console.log(res);
							let {city,province} = res.data.regeocode.addressComponent
							let cityName = city.length ? city : province
							context.commit('initCityMut',cityName)
						}
					})
					
				}
			})
		}
	}
}